import React, {Component} from 'react';
import {Button} from 'antd';
import store from '../../store/index';

//成员变量    不会随着数据改变而改变页面
//state变量  this.setState({})
class ReduxPage extends Component {
  state = {
    count: 0
  };

  componentDidMount() {
    store.subscribe(() => {
      this.setState({
        count: store.getState()
      })
    });
  }

  render() {
    let {count} = this.state;
    return (
      <div>
        <Button onClick={() => {
          store.dispatch({type: 'DECREMENT'})
        }}>-</Button>
        {count}
        <Button onClick={() => {
          store.dispatch({type: 'INCREMENT'})
        }}>+</Button>
      </div>
    );
  }
}

export default ReduxPage;
